<template>
  <div>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('udf:udfCycleType:save')" type="primary" @click="addOrUpdateHandle()">
            {{ $t('add') }}</el-button>
          <el-button v-if="$hasPermission('udf:udfCycleType:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize @select-change="dataListSelectionChangeHandleVex"
        @select-all="dataListSelectionAllChangeHandleVex" :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="typeCode" title="代码" width="100">
        </vxe-table-column>
        <vxe-table-column field="typeName" title="周期">
        </vxe-table-column>
        <vxe-table-column field="remark" title="备注说明">
        </vxe-table-column>
        <vxe-table-column field="startTime" title="提报规则" width="150">
          <template slot-scope="{row}">
            {{ formatRule(row) }}
          </template>
        </vxe-table-column>
        <!-- <vxe-table-column field="startTime" title="开始时间" width="100">
        </vxe-table-column>
        <vxe-table-column field="endTime" title="结束时间" width="100">
        </vxe-table-column>
        <vxe-table-column field="unit" title="单位" width="60" align="center">
        </vxe-table-column> -->
        <vxe-table-column field="updateDate" title="最后更新时间" width="140" align="center">
        </vxe-table-column>
        <vxe-table-column field="status" title="状态" width="70" align="center">
          <template slot-scope="{row}">
            <el-tag :type="row.status===1?'success':'danger'">{{ $getDictLabel('SYS_STATUS', row.status) }}</el-tag>
          </template>
        </vxe-table-column>
        <vxe-table-column title="handle" width="140" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('udf:udfCycleType:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('udf:udfCycleType:delete')" type="text" size="small" icon="el-icon-delete"
              @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
      </el-pagination>
       </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './udfCycleType-add-or-update'
import * as utils from './common/utils'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/udf/udfCycleType/page',
        getDataListIsPage: true,
        deleteURL: '/udf/udfCycleType',
        deleteIsBatch: true,
        exportURL: '/udf/udfCycleType/export'
      },
      dataForm: {
        typeCode: '',
        typeName: '',
        status: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    ...utils,
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
